package cn.iocoder.yudao.module.member.controller.app.jobCollection;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.member.controller.admin.job.vo.AppJobRespVO;
import cn.iocoder.yudao.module.member.controller.admin.jobcollection.vo.JobCollectionPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.jobcollection.vo.JobCollectionRespVO;
import cn.iocoder.yudao.module.member.controller.admin.jobcollection.vo.JobCollectionSaveReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.jobcollection.JobCollectionDO;
import cn.iocoder.yudao.module.member.service.jobcollection.JobCollectionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户 APP - 我的收藏")
@RestController
@RequestMapping("/member/collection")
@Validated
public class AppJobCollectionController {

    @Resource
    private JobCollectionService jobCollectionService;

    @PostMapping("/create")
    @Operation(summary = "创建我的收藏")
    @PermitAll
    public CommonResult<Long> createJobCollection(@Valid @RequestBody JobCollectionSaveReqVO createReqVO) {
        return success(jobCollectionService.createJobCollection(createReqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除我的收藏")
    @Parameter(name = "id", description = "编号", required = true)
    @PermitAll
    public CommonResult<Boolean> deleteJobCollection(@RequestParam("id") Long id) {
        jobCollectionService.deleteJobCollection(id);
        return success(true);
    }

    @DeleteMapping("/deleteJob")
    @Operation(summary = "删除我的收藏")
    @Parameter(name = "jobId", description = "编号", required = true)
    @PermitAll
    public CommonResult<Boolean> deleteJob(@RequestParam("jobId") Long jobId) {
        jobCollectionService.deleteJob(jobId);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得我的收藏")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PermitAll
    public CommonResult<JobCollectionRespVO> getJobCollection(@RequestParam("id") Long id) {
        JobCollectionDO jobCollection = jobCollectionService.getJobCollection(id);
        return success(BeanUtils.toBean(jobCollection, JobCollectionRespVO.class));
    }

    @GetMapping("/getUserId")
    @Operation(summary = "获得我的收藏")
    @PermitAll
    public CommonResult<Boolean> getJobCollectionUser(@RequestParam("jobId") Long jobId) {
        Boolean flag = jobCollectionService.getJobCollectionUser(getLoginUserId(),jobId);
        return success(flag);
    }

    @GetMapping("/page")
    @Operation(summary = "获得我的收藏分页")
    @PermitAll
    public CommonResult<PageResult<AppJobRespVO>> getJobCollectionPage(@Valid JobCollectionPageReqVO pageReqVO) {
        Long userId = getLoginUserId();
        pageReqVO.setUserId(userId);
        PageResult<AppJobRespVO> pageResult = jobCollectionService.getAppJobCollectionPage(pageReqVO);
        return success(pageResult);
    }

}